# -*- coding: utf-8 -*-
# author yzs
# date 2019-01-14
#
# 整除查询
# Description
# Given an array of positive integers and many queries for divisibility. In every query Q[i],
# we are given an integer K , we need to count all elements in the array which are perfectly divisible by K.
# Constraints:1<=T<=1001<=N,M<=1051<=A[i],Q[i]<=105
# Input
# The first line of input contains an integer T denoting the number of test cases.
# Then T test cases follow. Each test case consists of three lines.
# First line of each test case contains two integers N & M, second line contains N space separated array elements
# and third line contains M space separated queries.
# Output
# For each test case,In new line print the required count for each query Q[i].
# Sample Input 1 
# 2
# 6 3
# 2 4 9 15 21 20
# 2 3 5
# 3 2
# 3 4 6
# 2 3
# Sample Output 1
# 3 3 2
# 2 2


def count_perfect_num(arr_m, arr_n, m, n):
    result = []
    for i in range(n):
        num = 0
        for j in range(m):
            if arr_m[j] % arr_n[i] == 0:
                num = num + 1
        result.append(num)
    return result


while True:
    try:
        t = int(input().strip())
        for i in range(t):
            data = list(map(int, input().strip().split()))
            m, n = data[0], data[1]
            arr_m = list(map(int, input().strip().split()))[:m]
            arr_n = list(map(int, input().strip().split()))[:n]
            result = count_perfect_num(arr_m, arr_n, m, n)
            print(" ".join(str(i) for i in result))
    except EOFError:
        break

